package com.ruanxie.config;


import com.ruanxie.handle.CameraAndYoloWebSocketHandler;
import com.ruanxie.utils.CameraCaputureUtil;
import lombok.extern.slf4j.Slf4j;
import org.bytedeco.javacv.OpenCVFrameGrabber;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
@Slf4j
public class CameraAndYoloWebSocketConfig implements WebSocketConfigurer {


    @Bean//默认单例
    public CameraCaputureUtil cameraCaputureUtil(){
        log.info("创建cameraCaputureUtilBean对象...");
        CameraCaputureUtil cameraCaputureUtil = new CameraCaputureUtil();
        cameraCaputureUtil.setGrabber(new OpenCVFrameGrabber(0));
        return cameraCaputureUtil;
    }


    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new CameraAndYoloWebSocketHandler(), "/ws")
                .setAllowedOrigins("*");
    }


}
